package client.control;

import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Button;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import client.client;

public class RegController {
	@FXML TextField userField;
	@FXML PasswordField pass1;
	@FXML PasswordField pass2;
	@FXML TextField fnameField;
	@FXML TextField lnameField;
	@FXML ComboBox<String> cb;
	@FXML TextField answerField;
	@FXML Button cancelBtn;
	@FXML Button regBtn;

	client c;
	public void setC(client c){
		this.c = c;
	}

	@FXML public void register(ActionEvent event){
		if(userField.getText()==""||
			fnameField.getText()==""||
			lnameField.getText()==""||
			answerField.getText()==""||
			pass1.getText()==""||
			pass2.getText()==""){
			c.dia("blank fields not allowed");
		}else if(!pass1.getText().equals(pass2.getText())){
			c.dia("passwords do not match");
		}else{
			c.reg(lnameField.getText(),fnameField.getText(),
				userField.getText(), pass2.getText(), cb.getValue(),
				answerField.getText());
		}
	}


	public void setItems(ObservableList<String> items){
		cb.setItems(items);
	}

	@FXML public void close(ActionEvent event){
		cancelBtn.getScene().getWindow().hide();
	}

	public void itsOkna(){
		cancelBtn.getScene().getWindow().hide();
	}

}